package basicservicelogic

import (
	"context"
	"property_service/dao/model"
	"property_service/dao/query"
	"property_service/internal/svc"
	"property_service/property_service"
	"property_service/utils/result"

	"github.com/zeromicro/go-zero/core/logx"
)

type SupplierLevelAdditionAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSupplierLevelAdditionAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SupplierLevelAdditionAddLogic {
	return &SupplierLevelAdditionAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// SupplierLevelAdditionAdd 创建供应商级别信息
func (l *SupplierLevelAdditionAddLogic) SupplierLevelAdditionAdd(in *property_service.SupplierLevelAddition) (*property_service.Response, error) {
	// 获取供应商级别信息模型的查询构造器
	m := query.Use(l.svcCtx.Gorm).SupplierLevelAddition
	// 创建一个新的供应商级别信息模型对象，不包含ID、UpdatedAt、CreatedAt字段
	mod := &model.SupplierLevelAddition{
		SupplierLevelName: in.SupplierLevelName, // 供应商级别名称
		PronunciationCode: in.PronunciationCode, // 拼音简码
		SupplierPhone:     in.SupplierPhone,     //供应商人
		SupplierPerson:    in.SupplierPerson,    //供应商电话
		Address:           in.Address,           //供应商地址
		Remark:            in.Remark,            // 备注
		TenantID:          in.TenantID,          // 租户ID
		CreatedAtuser:     in.CreatedAtuser,     // 创建用户
	}

	// 使用上下文执行创建操作
	if err := m.WithContext(l.ctx).Create(mod); err != nil {
		// 如果创建失败，返回错误响应
		return result.Err(err).Ed()
	}
	// 创建成功，返回成功响应
	return result.Suc().AddEd()
}
